use bevy::{app::{App, Startup, Update}, color::{palettes::basic::AQUA, Alpha, Color}, core::Name, diagnostic::FrameTimeDiagnosticsPlugin, prelude::{BuildChildren, Commands, Component, Text}, text::{TextColor, TextFont, TextSpan}, ui::{Node, Val}, utils::default};

pub fn plugin(app: &mut App){
    app.add_plugins(FrameTimeDiagnosticsPlugin)
        .add_systems(Startup, setup)
        .add_systems(Update, update);
}

#[derive(Component)]
#[require(Text)]
pub struct PerformanceMatrix;


fn setup(mut commands: Commands){
    const ALPHA: f32 = 0.8;
    const FONT_SIZE: f32 = 12.0; 
    commands.spawn((
        Name::new("Performance matrix"),
        PerformanceMatrix,
        Node {
            position_type: bevy::ui::PositionType::Absolute,
            top: Val::Px(5.0),
            left: Val::Px(5.0),
            ..default()
        },
        )
    )
    .with_child((
        TextSpan::new("FPS  :"),
        TextFont::from_font_size(FONT_SIZE),
        TextColor(AQUA.with_alpha(ALPHA).into()),
    ))
    .with_child((
        TextSpan::new("\n"),
        TextFont::from_font_size(FONT_SIZE),
        TextColor(Color::default().with_alpha(ALPHA)),
    ))
    .with_child((
        TextSpan::new("FPS(SMA): "),
        TextFont::from_font_size(FONT_SIZE),
        TextColor(AQUA.with_alpha(ALPHA).into()),
    ));
}
fn update(){

}